<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){

        $this->display(T('Home@Article/index'));
    }

    public function search() {
        $articles=D('Article')->searchArticleByKeyword($_GET['keyword']);
        foreach ($articles as $key => $article) {
            $sort_data = D('Sort')->getSortById($article['sort_id']);
            $articles[$key]['sort'] = $sort_data[0]['name'];
            $user_data = (D('User')->getUserById($article['author_id']));
            $articles[$key]['author'] = $user_data[0]['username'];
            $comment_data = (D('Comment')->getCommentByArticleIdDesc($articles[$key]['id']));
            $articles[$key]['last_comment'] = $comment_data[0]['content'];
            $articles[$key]['last_comment_user_id'] = $comment_data[0]['from_id'];
            $last_comment_user = (D('User')->getUserById($comment_data[0]['from_id']));
            $articles[$key]['last_comment_user_name'] = $last_comment_user[0]['username'];
            $avatar_data = D('Avatar')->getAvatarById($user_data[0]['id']);
            $articles[$key]['avatar_name'] = $avatar_data[0]['name'];
        }
        $users=D('User')->searchUserByKeyword($_GET['keyword']);
//        dump($articles);
//        dump($users);
        $this->assign('articles',$articles);
        $this->assign('users',$users);
        $this->display(T('Home@index/search'));
    }


}